@extends('backend.template.bootstrap')
@section('content')
<div id="page-wrapper" >
    <div id="page-inner">
        <div class="row">
            <div class="col-md-12">
                <h1 class="page-header">
                    文章管理 <small>Articles.</small>
                </h1>
            </div>
        </div>
        <!-- /. ROW  -->
        <div class="row">
            <div class="col-md-12">
                <!-- Advanced Tables -->
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="panel-body">
                            <a href="{{ url('backend/articles/create') }}" class="btn btn-primary"><li class="fa fa-edit"></li> 写文章</a>
                            <br />
                            <br />
                            {!! Form::open(array('method' => 'get', 'url' => 'backend/articles', 'class' => 'form-inline')) !!}
	                            <div class="form-group">
				 					<label>标题</label>
	                            	{!! Form::text('title',  Input::get('title'), array('class' => 'form-control')) !!}
                            	</div>
                            	<div class="form-group">
                            		<label>分类</label>
	                            	{!! Form::select('categoryId', $categories, Input::get('categoryId'), array('class' => 'form-control')) !!}
                            	</div>
                            	<div class="form-group">
                            		<label>状态</label>
	                            	{!! Form::select('disabled', array('' => '全部', '0' => '正常', '1' => '禁用'), Input::get('disabled'), array('class' => 'form-control')) !!}
                            	</div>
				 				<button type="submit" class="btn btn-primary">立即查找</button>
                            {!! Form::close() !!}
                            <br />
                            <div class="table-responsive">
                                <table class="table">
                                    <thead>
                                    <tr>
                                        <th>标题</th>
                                        <th>分类</th>
                                        <th>点赞</th>
                                        <th>评论</th>
                                        <th>浏览</th>
                                        <th>文章状态</th>
                                        <th width="15%">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($articles as $article)
                                        <tr class="">
                                            <td>{{ $article->title }}</td>
                                            <td>{{ $article->category->name }}</td>
                                            <td>{{ $article->goods }}</td>
                                            <td>{{ count($article->comments) }}</td>
                                            <td>{{ $article->read }}</td>
                                            <td>
                                                @if($article->disabled)
                                                  	 已禁用
                                                @else
                                                	 正常
                                                @endif
                                            </td>
                                            <td>
                                                <a class="btn btn-sm btn-default" href="{{ url('backend/articles/'. $article->id .'/edit') }}">编辑</a> 
                            					{!! Form::open(array('method' => 'post', 'url' => 'backend/articles/'. $article->id .'/change-state', 'style' => 'display:inline-block;')) !!}
                            						@if($article->disabled)
                            							{!! Form::hidden('disabled', false) !!}	
                                                		<button type="submit" class="btn btn-sm btn-success">启用</button>
                            						@else
                            							{!! Form::hidden('disabled', true) !!}
                                                		<button type="submit" class="btn btn-sm btn-warning">禁用</button>
                            						@endif 
                                                {!! Form::close() !!}
                                                {!! Form::open(array('method' => 'delete', 'url' => 'backend/articles/'. $article->id, 'style' => 'display:inline-block;', 'onSubmit' => 'return confirm("确认删除？删除后不可恢复！")')) !!}
                                                <button type="submit" class="btn btn-sm btn-danger">删除</button>
                                                {!! Form::close() !!}
                                            </td>
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                                {!! $articles->render() !!}
                            </div>
                        </div>
                    </div>
                </div>
                <!--End Advanced Tables -->
            </div>
        </div>
    </div>
    <!-- /. PAGE INNER  -->

</div>
@endsection